<%@ page contentType="text/html;charset=UTF-8"
    import=
    "ro.romanescu.loc4j.Localization,
    ro.romanescu.loc4j.Dictionary,
    ro.romanescu.loc4j.impl.LocalizationImpl,
    ro.romanescu.loc4j.web.Loc4JTag,
    java.net.URL" 
%>
<%@ taglib uri="WEB-INF/classes/loc4j.tld" prefix="loc4j" %>
<%
  Localization loc4j = ( Localization )application.getAttribute( Loc4JTag.LOC4J_LOCALIZATION );
  String currentLanguage = ( String )application.getAttribute( Loc4JTag.LOC4J_LANGUAGE );
  Dictionary[] dics = loc4j.getDictionaries();
  
  String chl = request.getParameter( "chl" );
  if( chl != null )
  {
    String current_language = request.getParameter( "current_language" );
    application.setAttribute( Loc4JTag.LOC4J_LANGUAGE, current_language );
  }
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Welcome to loc4j!</title>
  </head>
  <body>
    <h1>
      <loc4j:text key="index.title" />
    </h1>
    <br />
    <div>
      <loc4j:text key="index.description" />
    </div>
    <br />
    <div>
      <loc4j:text key="index.avail" />
      <ul>
<%
for( int i = 0; i < dics.length; i++ ) {
  Dictionary dic = dics[ i ];
%>
        <li><%=dic.getLanguageName()%></li>
<%            
}
%>
      </ul>
      <br />
<%
  currentLanguage = ( String )application.getAttribute( Loc4JTag.LOC4J_LANGUAGE );
  Dictionary cDic = loc4j.getDictionary( currentLanguage );
%>
      <loc4j:text key="index.currLang" />: <strong><%=cDic.getLanguageName()%></strong>
      <br />      
      <loc4j:text key="index.sel" />
      <form action="" method="get">     
        <input type="hidden" name="chl" value="do" />
        <select name="current_language">
<%

for( int i = 0; i < dics.length; i++ ) {
  Dictionary dic = dics[ i ];     
  String selected = "";
  if( dic.getLanguageISOCode().equals( currentLanguage ) )
  {
    selected = "selected=\"selected\"";
  }
%>
          <option value="<%=dic.getLanguageISOCode()%>" <%=selected%>><%=dic.getLanguageNameNative()%></option>
<%
}
%>
        </select>
        <input type="submit" name="Change" value="<loc4j:text key="index.change" trim="true" />" />
</form>        
    </div>
  </body>
</html>